﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DomainModel.Entities;
using NHibernate;
using NHibernate.Criterion;
using DomainModel.Abstract;

namespace DomainModel.Concrete
{
    public class CommentsRepository: ICommentsRepository
    { 

        public IEnumerable<Comment> GetAll()
        {
            ICriteria criteria = SessionManager.CurrentSession.CreateCriteria(typeof(Comment)).AddOrder(Order.Desc("CommentID"));
            return criteria.List<Comment>();
        }


        public void Save(Comment item)
        {
            ISession session = SessionManager.CurrentSession;
            session.BeginTransaction();
            session.SaveOrUpdate(item);
            session.Transaction.Commit();
        }

        public void Delete(int id)
        {
            SessionManager.CurrentSession.Delete(Get(id));
        }

        public Comment Get(int id)
        {
            return SessionManager.CurrentSession.Get<Comment>(id);
        }

    }
}
